package com.gtja.beoms.base;//package com.gtja.beoms.base;
//
//import cn.hutool.core.collection.CollectionUtil;
//import com.gtja.beoms.dao.QwAgentInfoDao;
//import org.quartz.*;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.scheduling.quartz.SchedulerFactoryBean;
//import org.springframework.stereotype.Component;
//
//import java.util.Map;
//
///**
// * @Author : Li
// * @Description :定时任务调度中心
// */
//@Component
//public class CronSchedulerJob {
//
//    @Value("${oms.job.name}")
//    private String jobName;
//
//    @Value("${oms.job.group}")
//    private String jobGroup;
//
//    @Value("${oms.job.cron}")
//    private String jobCron;
//
//    private Logger log = LoggerFactory.getLogger(CronSchedulerJob.class);
//
//    @Autowired
//    private SchedulerFactoryBean schedulerFactoryBean;
//
//    @Autowired
//    private QwAgentInfoDao qwAgentInfoDao;
//
//    /**
//     * @Description:启动所有定时任务
//     * @author Li
//     */
//    public void startJobs() {
//        try {
//            log.info(">>>>>>>>>>>>>>>定时任务开始执行<<<<<<<<<<<<<");
//            Scheduler scheduler = schedulerFactoryBean.getScheduler();
//            scheduler.start();
//            log.info(">>>>>>>>>>>>>>>定时任务执行结束<<<<<<<<<<<<<");
//        } catch (Exception e) {
//            throw new RuntimeException(e);
//        }
//    }
//
//    /**
//     * @Description:添加一个定时任务
//     * @author Li
//     */
//    public void addJob(String jobName, String group, String cron, Class<? extends Job> taskName, Map<String, Object> param)
//            throws SchedulerException {
//        Scheduler scheduler = schedulerFactoryBean.getScheduler();
//        JobDetail jobDetail = JobBuilder.newJob(taskName)
//                .withIdentity(jobName, group).build();
//        if (!CollectionUtil.isEmpty(param)) {
//            for (Map.Entry<String, Object> vo : param.entrySet()) {
//                jobDetail.getJobDataMap().put(vo.getKey(), vo.getValue());
//            }
//        }
//        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cron);
//        CronTrigger cronTrigger = TriggerBuilder.newTrigger().withIdentity(jobName, group)
//                .withSchedule(scheduleBuilder).build();
//        scheduler.scheduleJob(jobDetail, cronTrigger);
//    }
//
//    /**
//     * @Description: 移除一个任务
//     * @author LI
//     */
//    public void removeJob(String jobName, String group) {
//        try {
//            Scheduler scheduler = schedulerFactoryBean.getScheduler();
//            scheduler.pauseTrigger(
//                    TriggerKey.triggerKey(jobName, group));// 停止触发器
//            scheduler.unscheduleJob(TriggerKey.triggerKey(jobName, group));// 移除触发器
//            scheduler.deleteJob(JobKey.jobKey(jobName, group));// 删除任务
//        } catch (Exception e) {
//            throw new RuntimeException(e);
//        }
//    }
//
//}